JavaScript interview question on array